package ups.Wind;

import java.util.Date;
import java.text.SimpleDateFormat;

public class WindRecord {
	enum DIRECTION { NORTH, NORTHWEST, NORTHEAST,
					 SOUTH, SOUTHWEST, SOUTHEAST,
					 EAST, EAST_SOUTHEAST, EAST_NORTHEAST,
					 WEST, WEST_SOUTHWEST, WEST_NORTHWEST,
					 INVALID};
	private Date 		_date;
	private int 		_temperature;
	private DIRECTION 	_direction;
	private int 		_speed;
	
	/* Regular constructor */
	public WindRecord( Date date, int temperature, DIRECTION direction, int speed) {
		initialize( date, temperature, direction, speed );
	}
	//Thursday November 02,2006 00:20	
	SimpleDateFormat format = new SimpleDateFormat( "EEEEEEEEE MMMMMMMMM d,yyyy  hh:mm");
	//DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.SHORT );
	
	/* Constructor for Strings */
	public WindRecord( String dateString, String temperature, String direction, String speed) {
		Date date;
		try {
			date = format.parse( dateString );
		} catch( Exception e ) {
			date = new Date();
			e.printStackTrace();
			System.out.println("Today's date in this format:");
			System.out.println( format.format( date ));
			System.exit(-1);
		}
		int temp = Integer.parseInt( temperature );
		DIRECTION dir = this.directionForString( direction );
		int spd = Integer.parseInt( speed );

		initialize( date, temp, dir, spd);
	}
	
	private final void initialize( Date date, int temperature, DIRECTION direction, int speed ) {
		_date 			= date;
		_temperature 	= temperature;
		_direction 		= direction;
		_speed 			= speed;
		
		System.out.println( this.toString() );
	}
	
	public DIRECTION directionForString( String direction ) {
		DIRECTION dir;
		if( direction.equals( "North")) {
			dir = DIRECTION.NORTH;
		} else if ( direction.equals( "Northwest")) {
			dir = DIRECTION.NORTHWEST;				
		} else if ( direction.equals( "Northeast")) {
			dir = DIRECTION.NORTHEAST;				
		} else if ( direction.equals( "South")) {
			dir = DIRECTION.SOUTH;				
		} else if ( direction.equals( "Southwest")) {
			dir = DIRECTION.SOUTHWEST;				
		} else if ( direction.equals( "Southeast")) {
			dir = DIRECTION.SOUTHEAST;				
		} else if ( direction.equals( "East")) {
			dir = DIRECTION.EAST;				
		} else if ( direction.equals( "East Southeast")) {
				dir = DIRECTION.EAST_SOUTHEAST;				
		} else if ( direction.equals( "East Northeast")) {
			dir = DIRECTION.EAST_NORTHEAST;				
		} else if ( direction.equals( "West")) {
			dir = DIRECTION.WEST;				
		} else if ( direction.equals( "West Southwest")) {
			dir = DIRECTION.WEST_SOUTHWEST;				
		} else if ( direction.equals( "West Northwest")) {
			dir = DIRECTION.WEST_NORTHWEST;				
		} else {
			System.out.println( " INVALID DIRECTION: " + direction );
			dir = DIRECTION.INVALID; // BAD
		}
		
		return dir;
	}

	public Date getDate() {
		return _date;
	}

	public void setDate(Date date) {
		this._date = date;
	}

	public DIRECTION getDirection() {
		return _direction;
	}

	public void setDirection(DIRECTION direction) {
		this._direction = direction;
	}

	public int getSpeed() {
		return _speed;
	}

	public void setSpeed(int speed) {
		this._speed = speed;
	}

	public int getTemperature() {
		return _temperature;
	}

	public void setTemperature(int temperature) {
		this._temperature = temperature;
	}
	
	public String toString() {
		return getDate().toString() + " " + getTemperature() + " " + getDirection().toString() + " " + getSpeed() + " " + " " + "\n";
	}
}
